package;

import nme.display.MovieClip;
import nme.display.SimpleButton;
import nme.events.MouseEvent;
import nme.events.Event;
import nme.display.Bitmap;
import nme.ui.Keyboard;
import nme.Lib;
import nme.events.KeyboardEvent;

/**
 * @author jonathanmoriarty
 */
class PauseScreen extends MovieClip, implements Screen
{
	// SFXR for mac sound generator
	// TODO: Add an animated background.
	private var _title:Bitmap;
	inline private static var TITLE_Y:Int = 50;
	
	private var _resume:Bitmap;
	inline private static var RESUME_Y:Int = 150;
	
	private var _options:Bitmap;
	inline private static var OPTIONS_Y:Int = 200;
	
	private var _quit:Bitmap;
	inline private static var QUIT_Y:Int = 250;
	
	public var select:Bitmap;
	
	public var confirmed:Bool;
	
	public function new() 
	{
		super();
		confirmed = false;
		trace("this gets called");
		
		_title = Tools.loadBitmap( "pause_title" );
		_title.x = THF.STAGE_WIDTH/2 - _title.width/2;
		_title.y = TITLE_Y;
		addChild(_title);
		
		_resume = Tools.loadBitmap( "pause_resume" );
		_resume.x = THF.STAGE_WIDTH/2 - _resume.width/2;
		_resume.y = RESUME_Y;
		addChild(_resume);
		
		_options = Tools.loadBitmap( "pause_options" );
		_options.x = THF.STAGE_WIDTH/2 - _options.width/2;
		_options.y = OPTIONS_Y;
		addChild(_options);
		
		_quit = Tools.loadBitmap( "pause_quit" );
		_quit.x = THF.STAGE_WIDTH/2 - _quit.width/2;
		_quit.y = QUIT_Y;
		addChild(_quit);
		
		select = Tools.loadBitmap( "pause_select_arrows" );
		select.x = THF.STAGE_WIDTH/2 - select.width/2;
		select.y = RESUME_Y;
		addChild(select);
		
		show();
	}
	
	public function update( l_deltaTime:Int ):Void
	{
		if ( !confirmed )
		{
			if ( InputManager.isKeyPressed( InputManager.UP_KEY ) && select.y > RESUME_Y )
			{
				select.y -= 50;
			}
				
			if ( InputManager.isKeyPressed( InputManager.DOWN_KEY ) && select.y < QUIT_Y )
			{
				select.y += 50;
			}
			
			if ( InputManager.isKeyPressed( InputManager.ENTER_KEY ) )
			{
				confirmed = true;
			}
		}
	}
	
	public function getSelectedOption():Int
	{
		if (select.y == RESUME_Y)
		{
			return 0;
		}
		else if (select.y == OPTIONS_Y)
		{
			return 1;
		}
		else
		{
			return 2;
		}
	}
	
	public function show():Void
	{
		this.visible = true;
		//_playButton.addEventListener( MouseEvent.CLICK, _onClickPlay );
		//_creditsButton.addEventListener( MouseEvent.CLICK, _onClickCredits );
		//_quitButton.addEventListener( MouseEvent.CLICK, _onClickQuit );
	}
	
	public function hide():Void
	{
		this.visible = false;
	}
	
	public function reset():Void
	{
		// nothing needed here at the moment.
	}
	
	public function destroy():Void
	{
		hide();
	}

}